#define _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    int get_val(int n)
    {
        int num = 0, val = 0;
        while (n > 0)
        {
            num = n % 10;
            n /= 10;
            val += num * num;
        }
        return val;
    }
    bool isHappy(int n) {
        int fast = get_val(n), slow = n;
        while (fast != slow)
        {
            slow = get_val(slow);
            fast = get_val(get_val(fast));
        }
        return slow == 1;
    }
};